package cn.baddonkey.superqueryjavasdk.json;

import cn.baddonkey.superqueryjavasdk.constant.JsonClassNameConstant;

public class JsonParserFactory {
    /**
     * 按顺序获取 json parser 未获取到返回 null
     *
     * @return json parser
     */
    public static JsonParser newInstance() {
        try {
            Class.forName(JsonClassNameConstant.FASTJSON);
            return new FastjsonParser();
        } catch (ClassNotFoundException ignored) {
        }

        try {
            Class.forName(JsonClassNameConstant.JACKSON);
            return new JacksonParser();

        } catch (ClassNotFoundException ignored) {
        }

        try {
            Class.forName(JsonClassNameConstant.GSON);
            return new GsonParser();
        } catch (ClassNotFoundException e) {
            return new NoneParser();
        }
    }
}
